from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from xgboost import XGBClassifier
from sklearn.metrics import accuracy_score
def  xgboost_demo():
    iris = load_iris()
    X = iris.data  # 特征数据
    y = iris.target  # 目标变量

    # 划分数据集
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)

    # 分类
    model = XGBClassifier()
    model.fit(X_train,y_train)

    # 预测
    y_pred = model.predict(X_test)

    #模型评估
    print(accuracy_score(y_test,y_pred))

if __name__ == '__main__':
    xgboost_demo()